<?php

namespace app\api\controller;

use app\api\model\User as UserModel;
use app\store\model\Order as OrderModel;

/**
 * 用户管理
 * Class User
 * @package app\api
 */
class User extends Controller
{
    /**
     * 用户自动登录
     * @return array
     * @throws \app\common\exception\BaseException
     * @throws \think\Exception
     * @throws \think\exception\DbException
     */
    public function login()
    {
        $model = new UserModel;
        return $this->renderSuccess([
            'user_id' => $model->login($this->request->post()),
            'token' => $model->getToken()
        ]);
    }

    /**
     * 当前用户详情
     * @return array
     * @throws \app\common\exception\BaseException
     * @throws \think\exception\DbException
     */
    public function detail()
    {
        // 当前用户信息
        $userInfo = $this->getUser();
        return $this->renderSuccess(compact('userInfo'));
    }


    public function ceshi(){
        // 订单列表
        $model = new OrderModel;
        $list = $model->getList('all', '');
        foreach ($list as $key => $val){
            $value['bianhao'] =sprintf("%06d",$key+1);
            $model->allowField('bianhao')->isUpdate()->save($val,['order_id'=>$val['order_id']]);
        }
    }

}
